﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VipSys.Business;
using VipSys.DataLayer;
using VipSys.SystemEntity;
using VipSys.Common;
using System.Drawing;

namespace VipSys.website
{
    public partial class UserInfo : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.InitUserInfo();
                this.InitRoomieInfo();
            }
        }

        private void InitUserInfo()
        {
            User user=new User();
            short shRet= UserAccess.Instance.GetUser(SystemParam.Instance.SysAccount.ID.ToString(), ref user);
            if (shRet != SystemData.ReturnValue.OK)
                return;
            this.txtName.Text = user.Name;
            this.txtBaks.Text = user.Bak;
            this.txtExamSchool.Text = user.ExamSchool;
            this.txtSchool.Text = user.School;
            this.txtGender.Text = user.Gender;
            this.txtHotel.Text = user.Hotel;
            this.txtRoom.Text = user.Room;
            this.txtMoneyBack.Text = user.MoneyBack;
            this.txtExamPlace.Text = user.ExamPlace;
            this.txtHotelExpense.Text = user.HotelExpense;
           
        }
        private void InitRoomieInfo()
        { 
            string szRoom=SystemParam.Instance.SysAccount.Room;
            string szHotel=SystemParam.Instance.SysAccount.Hotel;
            if(string.IsNullOrEmpty(szRoom)||string.IsNullOrEmpty(szHotel))
                return;
            List<User> lstUser=new List<User>();
            short shRet = UserAccess.Instance.GetUserList(szRoom, szHotel, ref lstUser);
            if (shRet != SystemData.ReturnValue.OK)
                return;
            for (int index = 0; index < lstUser.Count; index++)
            {
               
                User user = lstUser[index];
                if (user.ID == SystemParam.Instance.SysAccount.ID)
                    continue;
                HyperLink hlk = new HyperLink();
                hlk.Text = user.Name+" ";
                hlk.ForeColor = Color.Blue;
                hlk.NavigateUrl = string.Format("RoomieInfo.aspx?ID={0}",user.ID);
                this.panelRoomie.Controls.Add(hlk);
                
            }
        }
        protected void btnChange_Click(object sender, EventArgs e)
        {
            EnableChangeTxt();
            
        }

        private void EnableChangeTxt()
        {
            this.btnSave.Visible = true;
            this.btnChange.Visible = false;
            this.txtName.Enabled = true;
            this.txtBaks.Enabled = true;
            this.txtSchool.Enabled = true;
            this.txtExamSchool.Enabled = true;
            this.txtGender.Enabled = true;
        }
        private void DisableChangeTxt()
        {
            this.btnSave.Visible = false;
            this.btnChange.Visible = true ;
            this.txtName.Enabled = false;
            this.txtBaks.Enabled = false;
            this.txtSchool.Enabled = false;
            this.txtExamSchool.Enabled = false;
            this.txtGender.Enabled = false;
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            User user = new User();
            short shRet = UserAccess.Instance.GetUser(SystemParam.Instance.SysAccount.ID.ToString(), ref user);
            if (shRet != SystemData.ReturnValue.OK)
                return;
            user.Name = txtName.Text;
            user.School = txtSchool.Text;
            user.ExamSchool = txtExamSchool.Text;
            user.Gender = txtGender.Text;
            user.Bak = txtBaks.Text;
            shRet = UserAccess.Instance.Edit(user);
            if (shRet != SystemData.ReturnValue.OK)
            {
                this.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改失败')</script>");
                return;
            }
            this.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改成功')</script>");
            this.DisableChangeTxt();
        }
    }
}